import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class ConnectionManagement {
	
	private String url;
	private String username;
	private String password;
	
	private static Connection con;
	
	public ConnectionManagement(){
		this("jdbc:oracle:thin:@192.168.178.185:1521:orcl","kps14","kps14");
	}
	
	public ConnectionManagement(String url,String username, String password){
		this.url = url;
		this.username = username;
		this.password = password;
		try{
			// 1. Loading and Registering driver
			Class.forName("oracle.jdbc.OracleDriver");
			
			// 2. Establishing a Connection 
			con = DriverManager.getConnection(url,username,password);
			System.out.println("success");
		}catch(ClassNotFoundException ex){
			System.out.println(ex.getMessage());
		}catch(SQLException ex){
			System.out.println(ex.getMessage());
		}
	}	
	// Get the connection object
	public static Connection getConnection(){
		return con;
	}
	
	// Close the connection
	public static void closeConnection(){
		if(con!=null){
			try {
				con.close();
			} catch (SQLException ex) {
				System.out.println(ex.getMessage());
			}
		}
	}
	
	
}
